package com.example.guiguiapplicatio.utils;

import com.example.guiguiapplicatio.api.Interface.Api;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiUtils {
    private Retrofit retrofit;
    private static OkHttpClient client = null;
    private Api api;
    public ApiUtils(String baseUrl) {

        client = new OkHttpClient.Builder().
                //                 readTimeout(30, TimeUnit.SECONDS).
//                writeTimeout(30, TimeUnit.SECONDS).
        connectTimeout(6,TimeUnit.SECONDS).build();//用于设置请求超时等限制时间

        retrofit = new Retrofit.Builder()
                .client(client)
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        api = retrofit.create(Api .class);
    }
    public Api getApi() {
        return api;
    }
}
